Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reward distributor interval delay bug #891

Merged
merged 5 commits into from
Oct 30, 2024

Conversation

NoahSaso
Copy link
Member

@NoahSaso NoahSaso commented Oct 23, 2024

the reward distribution contract currently suffers a bug where reward distribution intervals are delayed each time a voting power change occurs.

this is due to the fact that integer division is used to make it so that only increments of the linear emission rate duration are distributed. when a voting power change occurs before one interval has passed, it calculates 0 new rewards distributed and updates the last updated timestamp, which effectively restarts the interval timer.

for example, if you distribute 100 tokens per hour:

  • at minute 0, timer starts counting
  • at minute 30, member stakes more tokens, and timer restarts
  • at minute 60, nothing happens
  • at minute 90, first distribution occurs

this PR fixes it so that it uses decimal math when counting the intervals that have passed since the last update in order to update the rewards distributed.

this also adds a force withdraw execution message to allow the contract owner to recover locked funds, since the delayed funds are likely stuck in the contract.

recover delayed/locked rewards

i think the ideal way to remedy this is:

  • pause all distributions
  • withdraw all undistributed funds from the distributions
  • upgrade the contract to fix the partial-interval distribution and add the force withdraw message
  • calculate the missed rewards by looking at what's left over in the contract and then looping through everyone's pending rewards and subtracting those from the left over amounts
  • force withdraw that unaccounted for amount, leaving all pending rewards that were successfully distributed intact
  • restart the distributions and fund them again

this way the state should be reset to account for the pending rewards that were allegedly distributed, and you can manually withdraw any funds beyond that amount before restarting and refunding.

@NoahSaso NoahSaso requested a review from bekauz October 23, 2024 02:36
…ire interval to finish, so that VP change doesn't delay distribution
@NoahSaso NoahSaso force-pushed the noah/partial-interval-reward-distribute branch from 418e5c1 to 56b204c Compare October 23, 2024 02:41
Copy link
Collaborator

@bekauz bekauz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall makes sense to me.

perhaps one thing that feels a bit extreme is the force withdraw. have you thought of possible alternatives to withdrawing? maybe some kind of re-accounting method would suffice?
main reason why I feel that way is just how the distributor contract is in a bit of a detached state after the force withdrawal. unless I'm missing something, wouldn't the queries return stale data?

@NoahSaso NoahSaso merged commit 83e9a98 into development Oct 30, 2024
5 of 7 checks passed
@NoahSaso NoahSaso deleted the noah/partial-interval-reward-distribute branch October 30, 2024 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants